package com.kintreda.ieco_server.util.api;

public class ResultData<T extends Object> {
	
	public static final int SUCCESS = 0;
	public static final int ERROR = -1;
	public static final String MESSAGE = "success";

	private int code;
	private String message;
	private String url;
	private T data;

	public ResultData() {
		this.code = SUCCESS;
		this.message = "";
		this.data = null;
	}

	public ResultData(int code, String message, T data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}
	
	public ResultData(int code, String message,String url, T data) {
		this.code = code;
		this.message = message;
		this.url = url;
		this.data = data;
	}

	public static <T extends Object> ResultData<T> newSuccess(int code, String message, T data) {
		return new ResultData<T>(code, message, data);
	}

	public static <T extends Object> ResultData<T> newSuccess(ResponseCode response, T data) {
		return new ResultData<T>(response.code, response.message, data);
	}
	
	public static <T extends Object> ResultData<T> newSuccess(String message,String url,T data) {
		return new ResultData<T>(SUCCESS, message,url,data);
	}

	public static <T extends Object> ResultData<T> newSuccess(String message, T data) {
		return new ResultData<T>(SUCCESS, message, data);
	}

	public static <T extends Object> ResultData<T> newSuccess(T data) {
		return new ResultData<T>(SUCCESS, MESSAGE, data);
	}

	public static <T extends Object> ResultData<T> newError(int code, String message) {
		return new ResultData<T>(code, message, null);
	}
	
	public static <T extends Object> ResultData<T> newError(int code, String message,String url,T data) {
		return new ResultData<T>(code, message,url,data);
	}
	
	public static <T extends Object> ResultData<T> newError(int code, String message,T data) {
		return new ResultData<T>(code, message,data);
	}

	public static <T extends Object> ResultData<T> newError(ResponseCode response) {
		return new ResultData<T>(response.code, response.message, null);
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}
}